home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / comm / misc / Camedia.lha / Camedia / camprg.c < prev    next >
C/C++ Source or Header  |  2001-06-07  |  22KB  |  761 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <exec/exec.h>
  8. #include <devices/serial.h>
  9. #include <jpeg/jpeg.h>
  10. #include <cybergraphics/cybergraphics.h>
  11. #include <intuition/intuition.h>
  12. #include <libraries/asl.h>
  13.  
  14. //#include <clib/exec_protos.h>        // TetiSoft
  15. //#include <clib/dos_protos.h>        // TetiSoft
  16. //#include <clib/intuition_protos.h>    // TetiSoft
  17. //#include <clib/asl_protos.h>        // TetiSoft
  18.  
  19. #include <proto/exec.h>            // TetiSoft
  20. #include <proto/dos.h>            // TetiSoft
  21. #include <proto/intuition.h>        // TetiSoft
  22. #include <proto/asl.h>            // TetiSoft
  23.  
  24. #include <clib/alib_protos.h>
  25. #include <clib/jpeg_protos.h>
  26. #include <clib/cybergraphics_protos.h>
  27.  
  28. //#include <pragma/exec_lib.h>        // TetiSoft
  29. //#include <pragma/dos_lib.h>        // TetiSoft
  30. //#include <pragma/intuition_lib.h>    // TetiSoft
  31. //#include <pragma/asl_lib.h>        // TetiSoft
  32.  
  33. #include <pragma/jpeg_lib.h>
  34. #include <pragma/cybergraphics_lib.h>
  35.  
  36. #include "Camedia.h"
  37.  
  38. // Added by TetiSoft (Since 01-Mar-2000, __AMIGADATE__ is one day in the future):
  39. char VerString[]="$VER: Camedia " VERSION " " __AMIGADATE__;
  40.  
  41. struct Library *JpegBase, *CyberGfxBase;
  42.  
  43. void info_f(enum Camera_Speed cs, char* error_msg);
  44. void preview_f(enum Camera_Speed cs, char* error_msg);
  45. void do_f(int user_min, int user_max, char *name, long speed, enum Camera_Speed cs, int action, char* error_msg);    // TetiSoft: Added enum
  46.  
  47. #ifdef __SASC
  48. void __regargs __chkabort(void)
  49. {
  50. }
  51. #endif
  52.  
  53. // void main(int argc, char *argv[]) {    // TetiSoft: Why not return result code to the shell?
  54. int main(void) {    // TetiSoft: We return result and don't need params
  55.     enum arg {
  56.         NONE = -2,
  57.         WRONG_MODE = -1,
  58.         DEVICE = 0, 
  59.         UNIT, 
  60.         SPEED, 
  61.         INFO,
  62.         PREVIEW,
  63.         TAKE_PICTURE,
  64.         RETR,
  65.         THUMBNAILS,
  66.         DEL,
  67.         FROM,
  68.         TO,
  69.         NAME};
  70.         
  71.     char *input_mask = "DEVICE/K,UNIT/N,SPEED/N,INFO/S,PREVIEW/S,TAKE_PICTURE/S,RETR/S,THUMBNAILS/S,DEL/S,FROM/N,TO/N,NAME/K";
  72.     enum Camera_Speed cs;
  73.     long speed/*=0*/;    // TetiSoft: No init necessary
  74.     int from=0, to=0, i, unit, modus = NONE;    // TetiSoft: from and to now initialized
  75.     LONG array[12];
  76.     struct RDArgs *rdargs;
  77.     char devicename[256], picture_name[256], error_msg[256];
  78.     
  79.     error_msg[0]='\0';
  80.  
  81.     for (i=0; i<12; i++) array[i]=0;
  82.     rdargs=ReadArgs(input_mask, array, NULL);
  83.     if (rdargs==NULL) {
  84.         printf("An error occured in ReadArgs(%s, array, NULL);\n", input_mask);
  85. //        exit(0);        // TetiSoft: No return code
  86.         return RETURN_FAIL;    // Added by TetiSoft
  87.     }
  88.     
  89.     /* DEVICE/K */
  90.     if (array[DEVICE]==0) strcpy(devicename, "serial.device");
  91.     else strcpy(devicename, (char *) array[DEVICE]);
  92.     
  93.     /* UNIT/N */
  94.     if (array[UNIT]!=0) unit=*((long *) array[UNIT]);
  95.     else unit=0;
  96.     
  97.     /* SPEED/N */
  98.     if (array[SPEED]==0) {
  99.         speed=19200;
  100.         cs=CAMERA_SPEED_19200;
  101.     } else {
  102.         speed=*((long *) array[SPEED]);
  103.     
  104.         switch (speed) {
  105.             case 9600:
  106.                 cs=CAMERA_SPEED_9600;
  107.                 break;
  108.             case 19200:
  109.                 cs=CAMERA_SPEED_19200;
  110.                 break;
  111.             case 38400:
  112.                 cs=CAMERA_SPEED_38400;
  113.                 break;            
  114.             case 57600:
  115.                 cs=CAMERA_SPEED_57600;
  116.                 break;
  117.             case 115200:
  118.                 cs=CAMERA_SPEED_115200;
  119.                 break;
  120.             case 230400:            // Added by TetiSoft
  121.                 cs=CAMERA_SPEED_230400;    // Added by TetiSoft
  122.                 break;            // Added by TetiSoft
  123.             default:
  124.                 // cs=CAMERA_SPEED_Unknown;
  125.                 printf("Unknown speed, must be either 9600, 19200, 38400, 57600, 115200 or 230400\n");    // TetiSoft: Added 230400
  126. //                exit(0);        // TetiSoft: No return code
  127.                 FreeArgs(rdargs);    // Added by TetiSoft
  128.                 return RETURN_ERROR;    // Added by TetiSoft
  129.         }
  130.     }
  131.         
  132.     /* INFO/S */ 
  133.     if ((int) array[INFO]) modus=INFO;
  134.     
  135.     /* PREVIEW/S */
  136.     if ((int) array[PREVIEW]) {
  137.         if (modus!=NONE) {
  138.             printf("Choose exactly one mode!\n");
  139.             modus=WRONG_MODE;
  140.         } else
  141.             modus=PREVIEW;
  142.     }
  143.     
  144.     /* TAKE_PICTURE/S */
  145.     if ((int) array[TAKE_PICTURE]) {
  146.         if (modus!=NONE) {
  147.             printf("Choose exactly one mode!\n");
  148.             modus=WRONG_MODE;
  149.         } else 
  150.             modus=TAKE_PICTURE;
  151.     }
  152.     
  153.     /* RETR/S */
  154.     if ((int) array[RETR]) {
  155.         if (modus!=NONE) {
  156.             printf("Choose exactly one mode!\n");
  157.             modus=WRONG_MODE;
  158.         } else {
  159.             modus=RETR;
  160.         }
  161.     }
  162.     
  163.     /* THUMBNAILS/S */
  164.     if ((int) array[THUMBNAILS]) {
  165.         if (modus!=NONE) {
  166.             printf("Choose exactly one mode!\n");
  167.             modus=WRONG_MODE;
  168.         } else {
  169.             modus=THUMBNAILS;
  170.         }
  171.     }
  172.     
  173.     /* DEL/S */
  174.     if ((int) array[DEL]) {
  175.         if (modus!=NONE) {
  176.             printf("Choose exactly one mode!\n");
  177.             modus=WRONG_MODE;
  178.         } else {
  179.             modus=DEL;
  180.         }
  181.     }
  182.     
  183.     if ((modus==RETR) || (modus==THUMBNAILS) || (modus==DEL)) {
  184.         /* FROM/N */
  185.         if (array[FROM]!=0) from=(int) *((long *) array[FROM]);
  186. //        else from=0;    // TetiSoft: No longer necessary
  187.     
  188.         /* TO/N */
  189.         if (array[TO]!=0) to=(int) *((long *) array[TO]);
  190. //        else to=0;    // TetiSoft: No longer necessary
  191.     
  192.         /* NAME/K */
  193.         if (array[NAME]==0) strcpy(picture_name, "Picture");
  194.         else strcpy(picture_name, (char *) array[NAME]);
  195.     }
  196.     
  197.     FreeArgs(rdargs);
  198.     
  199.     if (modus==NONE) {
  200.         printf("Choose one mode, which is Either INFO, PREVIEW, RETR, THUMBNAILS or DEL\n");
  201. //        exit(0);        // TetiSoft: No return code
  202.         return RETURN_ERROR;    // Added by TetiSoft
  203.     }
  204.     
  205.     bootstrap(devicename, unit, error_msg);
  206.     if (*error_msg!=0) {
  207.         printf("There was an error in bootstrap: %s\n", error_msg);
  208. //        exit(0);        // TetiSoft: No return code
  209.         return RETURN_ERROR;    // Added by TetiSoft
  210.     }
  211.     
  212.     switch (modus){
  213.         
  214.         case THUMBNAILS:
  215.             if (from==0) from=1;
  216.             if (to==0) to=255;
  217.             do_f(from, to, picture_name, speed, cs, 0, error_msg);
  218.             break;
  219.         
  220.         case RETR:
  221.             if (from==0) from=1;
  222.             if (to==0) to=255;
  223.             do_f(from, to, picture_name, speed, cs, 1, error_msg);
  224.             break;
  225.         
  226.         case DEL:
  227.             if (from==0) from=1;
  228.             if (to==0) to=255;
  229.             do_f(from, to, picture_name, speed, cs, 2, error_msg);
  230.             break;
  231.             
  232.         case TAKE_PICTURE:
  233.             // for this short code, I don't define a seperate function:)
  234.             init(cs, error_msg);
  235.             if (*error_msg==0) {
  236.                 TakeAction(AC_Take_Picture, 0, error_msg);
  237.                 // overwrite timeout_error, which is ok in this single case
  238.                 *error_msg=0;
  239.             }                
  240.             break;
  241.         
  242.         case PREVIEW:
  243.             preview_f(cs, error_msg);
  244.             break;
  245.             
  246.         case INFO:
  247.             info_f(cs, error_msg);
  248.             break;
  249.             
  250.         default:
  251.             printf("ops, there is somthing wrong with the mode\n");
  252.     }
  253.     clean(100);
  254.     if (*error_msg!=0) {
  255.         printf("There was an error: %s\n", error_msg);
  256.         return RETURN_ERROR;
  257.     } else {
  258.         printf("Well, all done\n");
  259.         return RETURN_OK;
  260.     }
  261. }
  262.  
  263.  
  264. void info_f(enum Camera_Speed cs, char* error_msg) {
  265.     int ResVal=Unknown_Resolution;        // Added by TetiSoft
  266.     enum Resolution *re=&ResVal;        // TetiSoft: Added enum, fixed NULL init
  267.     time_t cVal=0;                // Added by TetiSoft
  268.     time_t *c=&cVal;            // TetiSoft: Fixed NULL init
  269.     time_t TDVal=0;                // Added by TetiSoft
  270.     time_t *TimeDate=&TDVal;        // TetiSoft: Fixed NULL init
  271.     long ssVal=0;                // Added by TetiSoft
  272.     long *ss=&ssVal;            // TetiSoft: Fixed NULL init
  273.     int aVal=Unknown_Aperture;        // Added by TetiSoft
  274.     enum Aperture *a=&aVal;            // TetiSoft: Added enum, fixed NULL init
  275.     int cmVal=Unknown_Color_Mode;        // Added by TetiSoft
  276.     enum Color_Mode *cm=&cmVal;        // TetiSoft: Added enum, fixed NULL init
  277.     int fmVal=Unknown_Flash_Mode;        // Added by TetiSoft
  278.     enum Flash_Mode *fm=&fmVal;        // TetiSoft: Added enum, fixed NULL init
  279.     int noftVal=0;                // Added by TetiSoft
  280.     int *noft=&noftVal;            // TetiSoft: Fixed NULL init
  281.     int noflVal=0;                // Added by TetiSoft
  282.     int *nofl=&noflVal;            // TetiSoft: Fixed NULL init
  283.     int bcVal=0;                // Added by TetiSoft
  284.     int *bc=&bcVal;                // TetiSoft: Fixed NULL init
  285.     int aohtVal=0;                // Added by TetiSoft
  286.     int *aoht=&aohtVal;            // TetiSoft: Fixed NULL init
  287.     int aosoftVal=0;            // Added by TetiSoft
  288.     int *asoft=&aosoftVal;            // TetiSoft: Fixed NULL init
  289.     int lbVal=0;                // Added by TetiSoft
  290.     int *lb=&lbVal;                // TetiSoft: Fixed NULL init
  291.     int latVal=0;                // Added by TetiSoft
  292.     int *lat=&latVal;            // TetiSoft: Fixed NULL init
  293. //    int AELVal=0;                // Added by TetiSoft
  294. //    int *AEL_WBL=&AELVal;            // TetiSoft: Fixed NULL init
  295. //    int FEVal=0;                // Added by TetiSoft
  296. //    int *Fisheye=&FEVal;            // TetiSoft: Fixed NULL init
  297. //    int WideVal=0;                // Added by TetiSoft
  298. //    int *Wide=&WideVal;            // TetiSoft: Fixed NULL init
  299. //    int ZoomVal=0;                // Added by TetiSoft
  300. //    int *Digital_Zoom=&ZoomVal;        // TetiSoft: Fixed NULL init
  301. //    int BAWVal=0;                // Added by TetiSoft
  302. //    int *BAW=&BAWVal;            // TetiSoft: Fixed NULL init
  303. //    int LCDBVal=0;                // Added by TetiSoft
  304. //    int *LCD_Brightness=&LCDBVal;        // TetiSoft: Fixed NULL init
  305. //    int FTVal=0;                // Added by TetiSoft
  306. //    int *Frames_Taken=&FTVal;        // TetiSoft: Fixed NULL init
  307. //    int PSVal=0;                // Added by TetiSoft
  308. //    int *ProtectionState=&PSVal;        // TetiSoft: Fixed NULL init
  309.     int psofVal=0;                // Added by TetiSoft
  310.     int *psof=&psofVal;            // TetiSoft: Fixed NULL init
  311. //    int ccsVal=CAMERA_SPEED_Unknown;    // Added by TetiSoft
  312. //    enum Camera_Speed *ccs=&ccsVal;        // TetiSoft: Added enum, fixed NULL init
  313. //    int brcVal=Unknown_Bright_Contrast;    // Added by TetiSoft
  314. //    enum Bright_Contrast *brc=&brcVal;    // TetiSoft: Added enum, fixed NULL init
  315.     int wbVal=Unknown_White_Balance;    // Added by TetiSoft
  316.     enum White_Balance *wb=&wbVal;        // TetiSoft: Added enum, fixed NULL init
  317.     int dfVal=Unknown_Date_Format;        // Added by TetiSoft
  318.     enum Date_Format *df=&dfVal;        // TetiSoft: Added enum, fixed NULL init
  319.     int emVal=Unknown_Exp_Meter;        // Added by TetiSoft
  320.     enum Exp_Meter *em=&emVal;        // TetiSoft: Added enum, fixed NULL init
  321.     long amlVal=0;                // Added by TetiSoft
  322.     long *aml=&amlVal;            // TetiSoft: Fixed NULL init
  323.     long locfVal=0;                // Added by TetiSoft
  324.     long *locf=&locfVal;            // TetiSoft: Fixed NULL init
  325.     long loctVal=0;                // Added by TetiSoft
  326.     long *loct=&loctVal;            // TetiSoft: Fixed NULL init
  327.     long adl=0;                // Added by TetiSoft
  328.     long *AudioDataLength=&adl;        // TetiSoft: Fixed NULL init
  329.     int lmVal=Unknown_Lens_Mode;        // Added by TetiSoft
  330.     enum Lens_Mode *lm=&lmVal;        // TetiSoft: Added enum, fixed NULL init
  331.     int i, max;
  332.     char buf[1024];
  333.     long buflen;                // Added by TetiSoft
  334.  
  335.     init(cs, error_msg);
  336.     if (*error_msg!=0) return;
  337.  
  338.     Get_Resolution(re, error_msg);
  339.     if (*error_msg!=0) return;
  340.     printf("Resolution=%s\n", dump_Resolution(*re));
  341.  
  342.     Get_Clock(c, error_msg);
  343.     if (*error_msg!=0) return;
  344.     printf("Clock=%s", asctime(localtime(c)));    // TetiSoft: stripped \n
  345.         
  346.     Get_Shutter_Speed(ss, error_msg);
  347.     if (*error_msg!=0) return;
  348.     printf("Shutter_Speed=%d\n", *ss);
  349.  
  350.     Get_Aperture(a, error_msg);
  351.     if (*error_msg!=0) return;
  352.     printf("Aperture=%s\n", dump_Aperture(*a));
  353.  
  354.     Get_Color_Mode(cm, error_msg);
  355.     if (*error_msg!=0) return;
  356.     printf("Color_Mode=%s\n", dump_Color_Mode(*cm));
  357.         
  358.     Get_Flash_Mode(fm, error_msg);
  359.     if (*error_msg!=0) return;
  360.     printf("Flash_Mode=%s\n", dump_Flash_Mode(*fm));
  361.  
  362.     Get_Num_of_Frames_Taken(noft, error_msg);
  363.     if (*error_msg!=0) return;
  364.     printf("Number of Frames Taken=%d\n", *noft);
  365.     max=*noft;
  366.         
  367.     Get_Num_of_Frames_Left(nofl, error_msg);
  368.     if (*error_msg!=0) return;
  369.     printf("Number of Frames Left=%d\n", *nofl);
  370.         
  371.     Get_Battery_Capacity(bc, error_msg);
  372.     if (*error_msg!=0) return;
  373.     printf("Battery Capacity=%d\n", *bc);
  374. /*
  375.     Get_Comm_Speed(ccs, error_msg);
  376.       if (*error_msg!=0) return;
  377.      printf("Comm Speed=%s\n", dump_Camera_Speed(*ccs));
  378.  
  379.     Get_Bright_And_Contrast(brc, error_msg);
  380.      if (*error_msg!=0) return;
  381.     printf("Bright and Contrast=%s\n", dump_Bright_Contrast(*brc));
  382. */
  383.     Get_White_Balance(wb, error_msg);
  384.     if (*error_msg!=0) return;
  385.     printf("White Balance=%s\n", dump_White_Balance(*wb));
  386.     
  387.     Get_Autoshut_on_Host_Timer(aoht, error_msg);
  388.     if (*error_msg!=0) return;
  389.     printf("Autoshut on Host Timer=%d\n", *aoht);
  390.         
  391.     Get_Autoshut_on_Field_Timer(asoft, error_msg);
  392.     if (*error_msg!=0) return;
  393.     printf("Autoshut on Field Timer=%d\n", *asoft);
  394.     
  395.     Get_Available_Memory_Left(aml, error_msg);
  396.     if (*error_msg!=0) return;
  397.     printf("Available Memory Left=%d [Bytes]\n", *aml);
  398.         
  399.     Get_Lens_Mode(lm, error_msg);
  400.     if (*error_msg!=0) return;
  401.     printf("Lens Mode=%s\n", dump_Lens_Mode(*lm));
  402.         
  403.     Get_LCD_Brightness(lb, error_msg);
  404.     if (*error_msg!=0) return;
  405.     printf("LCD Brightness=%d\n", *lb);
  406.         
  407.     Get_LCD_Autoshut_Timer(lat, error_msg);
  408.     if (*error_msg!=0) return;
  409.     printf("LCD Autoshut Timer=%d\n", *lat);
  410.         
  411.     Get_Date_Format(df, error_msg);
  412.     if (*error_msg!=0) return;
  413.     printf("Date Format=%s\n", dump_Date_Format(*df));
  414.     
  415.     Get_Exp_Meter(em, error_msg);
  416.     if (*error_msg!=0) return;
  417.     printf("Exp Meter=%s\n", dump_Exp_Meter(*em));
  418. /*
  419.     Get_Optical_Mode(AEL_WBL, Fisheye, Wide, Digital_Zoom, BAW, error_msg);
  420.     if (*error_msg!=0) return;
  421.     printf("AEL_WB=%dL, Fisheye=%d, Wide=%d, Digital_Zoom=%d, BAW=%d\n", *AEL_WBL, *Fisheye, *Wide, *Digital_Zoom, *BAW);
  422. */
  423.     Get_Camera_ID(buf, &buflen, error_msg);            // TetiSoft: Fixed NULL pointer
  424.     if (*error_msg!=0) return;
  425.     printf("Camera ID=%s\n", (char *) buf);
  426.         
  427.     Get_Serial_Number(buf, &buflen, error_msg);        // TetiSoft: Fixed NULL pointer
  428.     if (*error_msg!=0) return;
  429.     printf("Serial Number=%s\n", buf);
  430.         
  431.     Get_Version(buf, &buflen, error_msg);            // TetiSoft: Fixed NULL pointer
  432.     if (*error_msg!=0) return;
  433.     printf("Version=%s\n", buf);
  434.         
  435.     Get_Model((char *) buf, &buflen, error_msg);        // TetiSoft: Fixed NULL pointer
  436.     if (*error_msg!=0) return;
  437.     printf("Model=%s\n", buf);
  438. /*
  439.     Get_Camera_Summery_Data(re, LCD_Brightness, Frames_Taken, error_msg);
  440.     if (*error_msg!=0) return;
  441.     printf("Resolution=%s, LCD Brightness=%d, Frames Taken=%d\n", dump_Resolution(*re), *LCD_Brightness, *Frames_Taken);
  442. */
  443.     Get_Manufacturer((char *) buf, &buflen, error_msg);    // TetiSoft: Fixed NULL pointer
  444.     if (*error_msg!=0) return;
  445.     printf("Manufacturer=%s\n", buf);
  446.  
  447.     if (max>0) {
  448.         i=1;
  449.         printf("There are %d frames taken\n", max);
  450.         while (i<=max && i<255) {
  451.             printf("Frame[%d]:\n", i);
  452.             Get_Length_of_Frame(i, locf, error_msg);
  453.             if (*error_msg!=0) return;
  454.             printf("   Length=%d\n", *locf);
  455.         
  456.             Get_Length_of_Thumbnail(i, loct, error_msg);
  457.             if (*error_msg!=0) return;
  458.             printf("   Length of Thumbnail=%d\n", *loct);
  459.                 Get_Protect_State_of_Frame(i, psof, error_msg);
  460.             if (*error_msg!=0) return;
  461.             printf("   Protection=%d\n", *psof);
  462.             
  463.             Get_Picture_Summery_Data(i, AudioDataLength, re, psof, TimeDate, error_msg);    // TetiSoft: Fixed three NULL pointers
  464.             if (*error_msg!=0) return;
  465. //            printf("   time stamp=%s\n", asctime(localtime(TimeDate)));    // TetiSoft: disabled
  466.             printf("   Resolution=%s\n   time stamp=%s\n", dump_Resolution(*re), asctime(localtime(TimeDate)));    // TetiSoft: Also show resolution
  467.             i++;
  468.         }
  469.     } else printf("There are no pictures in the camera\n");
  470. /*
  471.     {
  472.         // Added by TetiSoft: Reset serial speed of camera to default for next prg call, doesn't seem to work :-(
  473.         L1 r, initbyte=Computer_Initialization_Byte;
  474.         if (!error_msg[0]) send(&initbyte, 1, error_msg);
  475.         if (!error_msg[0]) read(&r, 1, error_msg);
  476.         if (!error_msg[0]) {
  477.             if (r==Camera_Signature) Set_Comm_Speed(CAMERA_SPEED_INIT, error_msg);
  478.             else printf("unexpected answer %d\n", r);
  479.         }
  480.         if (error_msg[0]) printf("%s\n", error_msg);
  481.     }
  482. */
  483. }
  484.  
  485.  
  486. void do_f(int user_min, int user_max, char *picture_name, long speed, enum Camera_Speed cs, int action, char* error_msg) {
  487.     time_t t;
  488.     time_t time1, time2;
  489.     char name[255], comment[80];
  490.     int i, max, passedtime, NoFT;
  491.     long size=0;
  492.     struct tm *tm_s;
  493.     long adl;    // Added by TetiSoft
  494.     int res;    // Added by TetiSoft
  495.     int prot;    // Added by TetiSoft
  496.     
  497.     if ((user_min<1) || (user_max<1) || (user_min>user_max)) {
  498.         printf("Can't accept such ranges\n");
  499.         return;
  500.     }
  501.     
  502.     init(cs, error_msg);
  503.     if (*error_msg!=0) return;
  504.  
  505.     Get_Num_of_Frames_Taken(&NoFT, error_msg);
  506.     if (*error_msg!=0) return;
  507.     
  508.     max=(int) NoFT;
  509.     if (max==0) {
  510.         printf("No pictures are stored in the camera.\n");
  511.         return;
  512.     }
  513.  
  514.     if (max<user_min) {
  515.         printf("There are %d pictures in the camera, not one more.\n", max);
  516.         printf("user_min=%d\n", user_min);
  517.         return;
  518.     }
  519.  
  520.     if (max<user_max) user_max=max;
  521.     
  522.     switch(action) {
  523.         case 0:
  524.             printf("Will get thumbnails %d to %d\n", user_min, user_max);
  525.             break;
  526.         case 1: 
  527.             printf("Will get pictures %d to %d\n", user_min, user_max);
  528.             break;
  529.         case 2: 
  530.             printf("Will delete pictures %d to %d\n", user_min, user_max);
  531.             break;
  532.         default:
  533.             printf("action has a wrong value %d\n", action);
  534.     }
  535.     
  536.     for(i=user_min; i<=user_max; i++) {
  537.     
  538.         if (action==0) {
  539.             sprintf(name, "%s_%d.jpeg", picture_name, i);
  540.             Get_Length_of_Thumbnail(i, &size, error_msg);
  541.             if (*error_msg!=0) return;
  542.             printf("Get thumbnail %d, size %d bytes, transfer time: about %d s\n", i, size, (int) 3+size/(speed/10));
  543.         }
  544.     
  545.         if (action==1) {
  546.             sprintf(name, "%s_%d.jpeg", picture_name, i);        
  547.             Get_Length_of_Frame(i, &size, error_msg);
  548.             if (*error_msg!=0) return;
  549.             printf("Get picture %d, size %d bytes, transfer time: about %d s\n", i, size, (int) 3+size/(speed/10));
  550.         }
  551.  
  552.         Get_Picture_Summery_Data(i, &adl, &res, &prot, &t, error_msg);    // TetiSoft: Fixed three NULL pointers
  553.         if (*error_msg!=0) return;
  554.             
  555.         tm_s = localtime(&t);
  556.         if (((tm_s->tm_year)<95) && ((tm_s->tm_year)>105)) strcpy(comment, "no date set");
  557.         else strftime(comment, 80, "%d-%b-%Y %H:%M:%S", tm_s );
  558.     
  559.         time(&time1);
  560.         switch (action) {
  561.             case 0:
  562.                 save_Thumbnail(i, name, comment, error_msg);
  563.                 if (*error_msg!=0) return;
  564.                 break;
  565.             case 1:
  566.                 save_Frame(i, name, comment, error_msg);
  567.                 if (*error_msg!=0) return;
  568.                 break;
  569.             case 2:
  570.                 SetIntegerRegister(Cmd_Set_Current_Frame_Number, (L1) i, error_msg);
  571.                 if (*error_msg!=0) return;
  572.                 TakeAction(AC_Erase_Current_Frame, 0, error_msg);
  573.                 if (*error_msg!=0) return;
  574.                 break;
  575.             default:
  576.                 printf("action has a wrong value %d\n", action);
  577.         }                
  578.         time(&time2);
  579.         passedtime=(int) time2-time1;
  580.         if (passedtime==0) passedtime=1;
  581. //        if ((action==0) || (action==1)) printf("%s, size %d, transfered in %d s, %5.0f cps\n", name, size, passedtime, ((float) size) / ((float) passedtime) );    // TetiSoft: Why float?
  582.         if ((action==0) || (action==1)) printf("%s, size %d, transfered in %d s, %d cps\n", name, size, passedtime, size/passedtime);                // TetiSoft: int should do it
  583.     } // end for
  584. }
  585.  
  586.  
  587. void preview_f(enum Camera_Speed cs, char* error_msg) {
  588.     struct JPEGDecHandle *jph;
  589.     struct Screen *scr;
  590.     struct Window *win;
  591.     struct Message *msg;
  592.     UBYTE *buffer/*=NULL*/;
  593.     UBYTE *frame_buffer/*=NULL*/;
  594.     ULONG DisplayID;
  595.     UWORD DisplayDepth;
  596.     struct ScreenModeRequester *smr;
  597.  
  598.     int err;
  599.     ULONG x, y, /*count,*/ bpp;
  600.     UBYTE colorspace;
  601.     long sizeVal;        // Added by TetiSoft
  602.     long *size=&sizeVal;    // TetiSoft: Fixed NULL init
  603.     BOOL r;
  604.         
  605.  
  606.     /* Open Libraries */
  607.     
  608.     JpegBase = OpenLibrary( "jpeg.library", NULL );
  609.     if (JpegBase==NULL) {
  610.         printf("Couldn't open jpeg.library\n");
  611.         return;
  612.     }
  613.     
  614.     CyberGfxBase = OpenLibrary( "cybergraphics.library", NULL );
  615.     if (JpegBase==NULL) {
  616.         printf("Couldn't open cybergraphics.library\n");
  617.         goto end5;
  618.     }
  619.     
  620.     /* Open ASL and ask user about screen */
  621.     
  622.     smr = (struct ScreenModeRequester* ) AllocAslRequestTags(ASL_ScreenModeRequest,
  623.         ASLSM_MinDepth, (ULONG) 15,
  624.         TAG_DONE);
  625.         
  626.     if (smr==NULL) {
  627.         printf("Couldn't do an AllocAslRequestTags()\n");
  628.         goto end4;
  629.     }
  630.     
  631.     r = AslRequest(smr, TAG_DONE);
  632.     if (!r) {
  633.         FreeAslRequest(smr);
  634.         printf("User did nothing?\n");
  635.         goto end4;
  636.     }
  637.     
  638.     DisplayID=smr->sm_DisplayID;
  639.     DisplayDepth=smr->sm_DisplayDepth;
  640.     FreeAslRequest(smr);
  641.     
  642.     /* Open Screen and Window */
  643.     
  644.     scr = OpenScreenTags( NULL,
  645.                                 SA_Title, "Camedia_Snapshot",
  646.                                 //SA_DisplayID, 0x40120051,
  647.                                 SA_DisplayID, DisplayID,
  648.                                 //SA_Depth, GetCyberIDAttr( CYBRIDATTR_DEPTH, 0x40120051),
  649.                                 SA_Depth, DisplayDepth,
  650.                                 TAG_DONE );
  651.     if (scr==NULL) {
  652.         printf("Couln't open screen\n");
  653.         goto end4;
  654.     }
  655.     
  656.     win = OpenWindowTags( NULL,
  657.                                 WA_Title, "Preview",                                
  658.                                 WA_Flags, WFLG_ACTIVATE | WFLG_SIMPLE_REFRESH |
  659.                                 WFLG_SIZEGADGET | WFLG_RMBTRAP | WFLG_DRAGBAR |
  660.                                 WFLG_DEPTHGADGET | WFLG_CLOSEGADGET,
  661.                                 WA_IDCMP, IDCMP_CLOSEWINDOW,
  662.                                 WA_Left, 0,
  663.                                 WA_Top, 0,
  664.                                 WA_Width, 500,
  665.                                 WA_Height, 380,
  666.                                 WA_MinWidth, 100,
  667.                                 WA_MinHeight, 70,
  668.                                 WA_MaxWidth, scr->Width,
  669.                                 WA_MaxHeight, scr->Height,
  670.                                 WA_AutoAdjust, 1,
  671.                                 WA_CustomScreen, scr,
  672.                                 TAG_DONE );
  673.  
  674.     if ( win == NULL ) {
  675.         printf("Couldn't open window\n");
  676.         goto end3;
  677.     }
  678.     
  679.     buffer=(UBYTE *) AllocMem(256000+6000, MEMF_CLEAR);
  680.     if (buffer==NULL) {
  681.         printf("No memory\n");
  682.         goto end2;
  683.     }
  684.     frame_buffer=buffer+256000;
  685.     
  686.     /* retrieve previews */
  687.     
  688.     init(cs, error_msg);
  689.     if (*error_msg!=0) {
  690.         printf("Error in init() %s\n", error_msg);
  691.         goto end2;
  692.     }
  693.     
  694.     for (;;) {
  695.         msg=GetMsg( win->UserPort );
  696.         if (msg!=NULL) {
  697.             ReplyMsg(msg);
  698.             while ( ( msg = GetMsg( win->UserPort ) ) != NULL ) ReplyMsg( msg );
  699.             goto end1;
  700.         }
  701.         
  702.         Get_Preview((UBYTE *) frame_buffer, size, error_msg);
  703.         if (*error_msg!=0) {
  704.             printf("Error in Get_Preview() %s\n", error_msg);
  705.             goto end1;
  706.         }
  707.  
  708.         /* Decode picture */
  709.         
  710.         err = AllocJPEGDecompress( &jph,
  711.                 JPG_SrcMemStream, frame_buffer,
  712.                 JPG_SrcMemStreamSize, *size,
  713.                 TAG_DONE );
  714.  
  715.         if (err!=0) {
  716.             printf("error in AllocJPEGDecompress\n");
  717.             goto end1;
  718.         }
  719.         err = GetJPEGInfo( jph,
  720.                                 JPG_Width, &x, JPG_Height, &y,
  721.                                 JPG_ColourSpace, &colorspace, 
  722.                                 JPG_BytesPerPixel, &bpp,
  723.                                 JPG_ScaleNum, 1, JPG_ScaleDenom, 1,
  724.                                 TAG_DONE );
  725.         
  726.         if (err!=0) {
  727.             printf("error in GetJPEGInfo\n");
  728.             FreeJPEGDecompress(jph);
  729.             goto end1;
  730.         }
  731.  
  732.         err = DecompressJPEG( jph,
  733.                                     JPG_DestRGBBuffer, buffer,
  734.                                     JPG_ScaleNum, 1, JPG_ScaleDenom, 1,
  735.                                     TAG_DONE );
  736.         if (err!=0) {
  737.             printf("error in DecompressJPEG(...)\n");
  738.             FreeJPEGDecompress(jph);
  739.             goto end1;
  740.         }
  741.     
  742.         /* Display picture */
  743.         /*count=*/ (ULONG) ScalePixelArray(buffer, x, y, (bpp*x), win->RPort, win->BorderLeft, win->BorderTop, win->GZZWidth, win->GZZHeight, RECTFMT_RGB);
  744.  
  745.         FreeJPEGDecompress(jph);
  746.     }
  747.     
  748.     /* Close Windows and Screen*/
  749.  
  750. end1:
  751.     FreeMem(buffer, 256000+6000);
  752. end2:
  753.     CloseWindow(win);
  754. end3:
  755.     CloseScreen(scr);
  756. end4:
  757.     /* Close Libraries */
  758.     CloseLibrary(CyberGfxBase);
  759. end5:
  760.     CloseLibrary(JpegBase);
  761. }